package io.renren.modules.shipping_area.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.shipping_area.dao.V9ShippingAreaDao;
import io.renren.modules.shipping_area.entity.V9ShippingAreaEntity;
import io.renren.modules.shipping_area.service.V9ShippingAreaService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("v9ShippingAreaService")
public class V9ShippingAreaServiceImpl extends ServiceImpl<V9ShippingAreaDao, V9ShippingAreaEntity> implements V9ShippingAreaService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String shipping_area_name = (String)params.get("shipping_area_name");
//        'shipping_area_name': this.dataForm.shipping_area_name,
//        'shipping_id':this.dataForm.shipping_id,
//        'order':this.dataForm.order,
//        'isasc':this.dataForm.isasc
        String shipping_id= (String)params.get("shipping_id");
        String order= (String)params.get("order");
        String isasc= (String)params.get("isasc");
        IPage<V9ShippingAreaEntity> page = this.page(
                new Query<V9ShippingAreaEntity>().getPage(params,"shipping_area_id",false),
                new QueryWrapper<V9ShippingAreaEntity>()
                .like(StringUtils.isNotBlank(shipping_area_name),"shipping_area_name", "%"+shipping_area_name+"%")
                .eq(StringUtils.isNotBlank(shipping_id), "shipping_id", shipping_id)
                .orderBy(StringUtils.isNotBlank(isasc), isasc.equals("ascending"), order)
        );

        return new PageUtils(page);
    }

	@Override
	public Integer insertGetId(V9ShippingAreaEntity vAreaEntity) {
		baseMapper.insert(vAreaEntity);
		return vAreaEntity.getShippingAreaId();
		 
	}

}